package cn.qiye.webflux.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import cn.hutool.core.io.IoUtil;

/**
 * description
 *
 * @author xikai.wang@hand-china.com 2025/9/22 11:50
 */
public class FileUtils {

    public static String readFileStr(String path){
        try {
            String dirStr=path.substring(0, path.lastIndexOf("/"));
            File dir=new File(dirStr);
            if(!dir.exists()){
                Files.createDirectory(Paths.get(dirStr));
            }
            File file=new File(path);
            return  readFileStr(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static String readFileStr(File file){
        StringBuilder result=new StringBuilder();
        try(BufferedReader reader = new BufferedReader(new FileReader(file));){
            while(reader.ready()){
                result.append(reader.readLine());
            }
        }catch (IOException e){
          throw new RuntimeException(e);
        }
        return result.toString();
    }
}
